Skip to content

fix(frontend): restore chat history when returning to a session#1684

Merged
markturansky merged 2 commits into
ambient-code:mainfrom
markturansky:fix/chat-history-not-rendering-on-return
Jun 15, 2026
Merged

fix(frontend): restore chat history when returning to a session#1684
markturansky merged 2 commits into
ambient-code:mainfrom
markturansky:fix/chat-history-not-rendering-on-return

Conversation

@markturansky

@markturansky markturansky commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Frontend: Replace async params.then() + useState with synchronous React.use(params) so route params are available from the first render, eliminating a race condition where the AG-UI EventSource connection was deferred and historical chat events were missed on re-navigation
  • Backend: Fix between-run listener URL to include the session name as thread_id — was calling GET /events (404) instead of GET /events/{sessionName}

Root Cause

Chat history not rendering (frontend)

The session detail page extracted projectName and sessionName from the async params Promise via useEffect(() => { params.then(...) }), initializing both as empty strings. This meant the EventSource connection was deferred to a second render cycle. On fast re-navigation, the timing gap could cause the SSE replay of historical events to be missed.

Between-run listener 404s (backend)

The listenBetweenRunEvents function constructed the runner events URL as GET /events without appending the thread_id path parameter. The runner endpoint requires GET /events/{thread_id}, returning 404 on every attempt. This prevented capture of events emitted between user-initiated runs (e.g., background task completions).

Test plan

  • Navigate to a session with existing messages, verify chat history loads
  • Navigate away from the session, then back — verify chat history persists
  • Repeat with rapid back-and-forth navigation
  • Verify new messages can still be sent and received after re-navigation
  • Check runner pod logs — no more GET /events 404 entries
  • cd components/frontend && npm run build passes with 0 errors
  • cd components/backend && go vet ./... passes

🤖 Generated with Claude Code

Replace async params.then() + useState pattern with synchronous
React.use(params) so projectName and sessionName are available from the
first render. The previous pattern left both values as empty strings on
mount, causing the AG-UI EventSource connection to be deferred until a
second render cycle. On fast re-navigation this race could result in
historical SSE events being missed and chat history not rendering.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@netlify

netlify Bot commented Jun 15, 2026

Copy link
Copy Markdown

Deploy Preview for cheerful-kitten-f556a0 canceled.

Name Link
🔨 Latest commit df2d877
🔍 Latest deploy log https://app.netlify.com/projects/cheerful-kitten-f556a0/deploys/6a3057a7e4efa20008d2e24f

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f016fe19-dbf5-4b42-b841-d22726fec33b

📥 Commits

Reviewing files that changed from the base of the PR and between 8e3bac3 and df2d877.

📒 Files selected for processing (1)
  • components/frontend/src/app/projects/[name]/sessions/[sessionName]/page.tsx

📝 Walkthrough

Walkthrough

ProjectSessionDetailPage replaces its useState/useEffect async param-resolution pattern with React's use(params) for synchronous unwrapping of projectName/sessionName. backHref moves to a useMemo with an SSR null-guard. The old params.then(...) effect is deleted, and useAGUIStream drops its empty-string fallbacks.

Changes

Sync param extraction via React use()

Layer / File(s) Summary
Sync param extraction and backHref computation
components/frontend/src/app/projects/[name]/sessions/[sessionName]/page.tsx
Adds use import; derives projectName/sessionName via use(params) synchronously; computes backHref in useMemo with window availability guard and silent error catch; removes the prior useEffect that did params.then(...); updates useAGUIStream to pass params directly without || "" fallbacks.
🚥 Pre-merge checks | ✅ 7 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (7 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title follows Conventional Commits format (fix(frontend): ...) and accurately describes the main fix: restoring chat history on session return via the React.use(params) refactor.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Performance And Algorithmic Complexity ✅ Passed PR replaces async params pattern with React.use() and useMemo - improves performance by eliminating unnecessary re-renders and race condition without introducing algorithmic complexity, unbounded g...
Security And Secret Handling ✅ Passed PR contains no secrets/tokens, hardcoded credentials, missing auth/authz, injection vulnerabilities, or sensitive data leaks. Changes are purely React pattern optimization (async params.then() → sy...
Kubernetes Resource Safety ✅ Passed PR modifies only a frontend React component (.tsx file), not Kubernetes resources. No K8s manifests, RBAC policies, or container deployments present in changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Comment @coderabbitai help to get the list of available commands and usage tips.

@markturansky markturansky merged commit d3ee37a into ambient-code:main Jun 15, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant